package com.leetcode.algorithm.y22.m09.w3;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 2331. 计算布尔二叉树的值
 * 
 * https://leetcode.cn/problems/evaluate-boolean-binary-tree/
 * 
 * @author jie.deng
 *
 */
class Question2331Solution01 {

	public boolean evaluateTree(TreeNode root) {
		if (root.left == null && root.right == null) {
			return root.val == 1;
		}
		boolean left = evaluateTree(root.left);
		boolean right = evaluateTree(root.right);
		if (root.val == 2) {
			return left | right;
		}
		return left & right;
	}

}